import 'package:flutter/material.dart';
import '../routers/application.dart';
import 'package:shared_preferences/shared_preferences.dart';

class IndexPage extends StatefulWidget {
	_IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage>with SingleTickerProviderStateMixin {
	TabController _tabController;
    String userName = "";
    String userCode = "";

	@override
	void initState() {
		_tabController = TabController(vsync: this, length: 3);
        getUserNameAndCode();
		super.initState();
	}

    void getUserNameAndCode(){
        Future<dynamic> future = Future(()async{
                SharedPreferences prefs =await SharedPreferences.getInstance();
                return [prefs.getString("userName"),prefs.getString("userCode")];
            });
            future.then((val){
                setState(() {
                  userName = val[0];
                  userCode = val[1];
                });
                // print(val);
            }).catchError((_){
                print("catchError");
            });
    }

  	@override
  	Widget build(BuildContext context) {
    	return Scaffold(
		appBar: AppBar(
			automaticallyImplyLeading: false,
			leading: Builder(
				builder: (context) => IconButton(
					icon: new Icon(Icons.menu),
					onPressed: () => Scaffold.of(context).openDrawer(),
					),
				),
			title: Text("恒一教育"),
			bottom: TabBar(
                tabs: <Widget>[
                    Tab(
                        icon: Icon(Icons.message),
                        text: "栏目一",
                    ),
                    Tab(
                        icon: Icon(Icons.mic),
                        text: "栏目二",
                    ),
                    Tab(
                        icon: Icon(Icons.minimize),
                        text: "栏目三",
                    )
                ],
                controller: _tabController,
			),
		),
        // body: Container(
        //     width: double.infinity,
        //     height: double.infinity,
        //     child: Image.asset(
        //         "image/temp.jpg",
        //         fit: BoxFit.fill,
        //     ),
        // ),
      body: TabBarView(
        controller: _tabController,
        children: <Widget>[
          	Center(
				child: Text("1"),
          	),
			Center(
				child: Text("2"),
			),
			Center(
				child: Text("3"),
			)
        ],
      ),
      drawer: Drawer(
				child: Container(
					child: Column(
					children: <Widget>[
						UserAccountsDrawerHeader(
						margin: EdgeInsets.all(0.0),
						accountName: new Text(userName),
						accountEmail: new Text(userCode),
						currentAccountPicture: CircleAvatar(
							backgroundImage: AssetImage("image/a.png"),
						),
						// onDetailsPressed: (){},
						// otherAccountsPictures: <Widget>[
						// 		new Container(
						// 				child: Image.asset("image/a.png"),
						// 		)
						// ],
						),
						Expanded(
							child: SingleChildScrollView(
                                child: Container(
                                    padding: EdgeInsets.all(0.0),
                                    child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: <Widget>[
                                            Container(
                                                height: 30.0,
                                                width: double.infinity,
                                                color: Colors.blue[100],
                                                child: Center(
                                                    child: Text("插件",style: TextStyle(color: Colors.black54),),
                                                ),
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("查询成绩"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/examList");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("图表示例"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("信息录入(相机)_2"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test2");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("flrs动画_3"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test3");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("上拉加载更多_4"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test4");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("地图示例_5(未完成)"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test5");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("生成二维码_6"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test6");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("扫描二维码_7"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test7");
                                                },
                                            ),
                                            Container(
                                                height: 30.0,
                                                width: double.infinity,
                                                color: Colors.blue[100],
                                                child: Center(
                                                    child: Text("UI",style: TextStyle(color: Colors.black54),),
                                                ),
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("AnimatedList_8"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test8");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("widget的AppBar_9"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test9");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("appbar带下拉菜单_10"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test10");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("可展开列表_11"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test11");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("选项卡式的AppBar_12"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test12");
                                                },
                                            ),
                                            Container(
                                                height: 30.0,
                                                width: double.infinity,
                                                color: Colors.blue[100],
                                                child: Center(
                                                    child: Text("其他",style: TextStyle(color: Colors.black54),),
                                                ),
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("画板_13"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test13");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("socket连接_14"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test14");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("table_24"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test24");
                                                },
                                            ),
                                            Container(
                                                height: 30.0,
                                                width: double.infinity,
                                                color: Colors.blue[100],
                                                child: Center(
                                                    child: Text("页面",style: TextStyle(color: Colors.black54),),
                                                ),
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("仿boss筛选模板_15"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test15");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("渐变appbar_16"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test16");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("沉浸式appbar_17"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test17");
                                                },
                                            ),
                                            ListTile(
                                                leading: Hero(
                                                    tag: "herodemo",
                                                    child: CircleAvatar(
                                                        child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                    ),
                                                ),
                                                title: Text("hero动画_18"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test18");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("ClipPath裁剪_19"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test19");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("我的页面_20"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test20");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("相机_21"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test21");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("底部弹窗_22"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test22");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("按钮动画_23"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test23");
                                                },
                                            ),
                                            ListTile(
                                                leading: new CircleAvatar(
                                                    child: Icon(IconData(0xec4c, fontFamily: "Iconfont"), size: 24.0),
                                                ),
                                                title: Text("AnimatedOpacity渐变动画_25"),
                                                onTap: (){
                                                    Application.router.navigateTo(context, "/test25");
                                                },
                                            ),
                                        ],
                                    )
                                ),
                            )
                        ),
						Container(
                            child: FlatButton.icon(
                                icon: Icon(Icons.settings),
                                label: Text("设置"),
                                // child: Text("设置"),
                                onPressed: () {
                                    Application.router.navigateTo(context, "/setting");
                                },
                            ),
						)
					],
					),
      			)
	  	),
    );
  }
}
